package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.dto.SpecParamDTO;
import com.leyou.common.exception.MyException;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamService extends ServiceImpl<SpecParamMapper, SpecParam> implements com.leyou.item.service.SpecParamService {
    @Override
    public List<SpecParamDTO> queryParams(Long categoryId, Long groupId, Boolean searching) {
        // 健壮性判断
        if(categoryId == null && groupId == null){
            // 条件不能都为空
            throw new MyException(400, "查询条件不能为空！");
        }
        // 查询
        List<SpecParam> list = query().eq(categoryId != null, "category_id", categoryId)
                .eq(groupId != null, "group_id", groupId)
                .eq(searching != null, "searching", searching)
                .list();
        return SpecParamDTO.convertEntityList(list);
    }
}
